package com.zhanglijie.theory.sigleThreadedExecutor;

import com.zhanglijie.base.sync.Lock.MySynchronized;
import com.zhanglijie.base.threadPool.myThreadPool.MyThreadPool;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/7/22 0022 0:55
 */
public class MySemphere {
    private int count;
    public MySemphere(int count){
        this.count = count;
    }
    public void acquire() throws InterruptedException {
       while(true){
           synchronized (this){
               if(count>0){
                   count--;
                   break;
               }
               this.wait();//线程卡死
           }
       }
    }
    public void release(){
        synchronized (this){
            this.count++;
            this.notifyAll();
        }
    }
}
